<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<style>
    .img-container{
        margin: 50px auto;
        width: 300px;
        height: 300px;
        display: grid;
        grid-template-columns: repeat(3,1fr);

    }

    .img-item{
        /*box-shadow: inset 0 0 0 1px #fff;*/
        /*border: 1px solid blue;*/
        background-size: 300px 300px;
        background-image: url("./img.png");
        position: relative;
        transition: all 0.5s;
    }

    .img-item:nth-child(3n+1){
        left: -20px;
        background-position-x: 0;
    }

    .img-item:nth-child(3n+2){
        background-position-x: -100px;
    }

    .img-item:nth-child(3n){
        left: 20px;
        background-position-x: -200px;
    }

/*    先选中所有 1-9 ，，然后选中1-6 覆盖之前的1-9，，，然后选中1-3覆盖之前的1-6*/
/*    .img-item{*/
/*        transform: translateY(20px);*/
/*        background-position-y: -200px;*/
/*    }*/

    .img-item{
        top: 20px;
        background-position-y: -200px;
    }

    .img-item:nth-child(-n+6){
        top: 0;
        background-position-y: -100px;
    }


    .img-item:nth-child(-n+3){
        background-position-y: 0;
        top: -20px;
        /*translate 会覆盖*/
    }

    .img-container:hover .img-item{
        top: 0;
        left: 0;
    }
</style>

<div class="img-container">
        <div class="img-item"></div>
        <div class="img-item"></div>
        <div class="img-item"></div>
        <div class="img-item"></div>
        <div class="img-item"></div>
        <div class="img-item"></div>
        <div class="img-item"></div>
        <div class="img-item"></div>
        <div class="img-item"></div>
</div>
</body>
</html>
